package com.todo.auth.controller;

import com.todo.auth.controller.request.LogOffAccountParam;
import com.todo.auth.controller.request.TransferPasswordParam;
import com.todo.auth.controller.request.UserNameLoginParam;
import com.todo.auth.controller.request.UserNameRegisterParam;
import com.todo.auth.controller.response.UserTokenVO;
import com.todo.auth.service.UserAccountLoginService;
import com.todo.common.common.entity.CurrentUser;
import com.todo.common.common.entity.response.BizResponse;
import com.todo.common.utils.TodoCommonUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author azhebuxing
 * @date 2025/2/20 00:40
 * @description
 */
@RestController
@RequestMapping("/auth/userAccount")
@Tag(name = "用户前台接口", description = "用户前台接口")
public class UserAccountLoginController {

    @Resource
    private UserAccountLoginService userAccountLoginService;

    @Operation(summary = "用户名注册")
    @PostMapping("/userNameRegister")
    public BizResponse<UserTokenVO> userNameRegister(@RequestBody UserNameRegisterParam param) {
        if (param == null || !param.checkParam()) {
            return BizResponse.paramError("操作失败，请刷新后重新操作");
        }
        return userAccountLoginService.registerByName(param);
    }

    @Operation(summary = "用户名登录")
    @PostMapping("/userNameLogin")
    public BizResponse<UserTokenVO> userNameLogin(@RequestBody UserNameLoginParam param) {
        if (param == null || !param.checkParam()) {
            return BizResponse.paramError("操作失败，请刷新后重新操作");
        }
        return userAccountLoginService.login(param);
    }

    @Operation(summary = "用户注销")
    @PostMapping("/logOffAccount")
    public BizResponse<Boolean> logOffAccount(@RequestBody LogOffAccountParam param) {
        if (param == null || !param.checkParam()) {
            return BizResponse.paramError("操作失败，请刷新后重新操作");
        }
        return userAccountLoginService.logOffAccount(param);
    }

    @Operation(summary = "用户修改密码")
    @PostMapping("/transferPassword")
    public BizResponse<UserTokenVO> transferPassword(@RequestBody TransferPasswordParam param) {
        if (param == null || !param.checkParam()) {
            return BizResponse.paramError("操作失败，请刷新后重新操作");
        }
        return userAccountLoginService.transferPassword(param);
    }
}
